© The Institution of Engineering and Technology 2020.The increasing penetration of distributed generation (DG) inverters supplying power to the networks bring challenges to the power system under the grid faulty and harmonic grid since negative sequence components lead to double oscillations. Reference current generation (RCG)-based flexible control strategies ensure solutions to mitigate oscillations on the control signals and to maintain a more stable, secure and reliable power system operation. In this direction, this study proposes an RCG-based optimal control strategy that reduces oscillations of active and reactive power at optimal control parameter values and ensures minimum harmonic contents at the grid side under an unbalanced and harmonic distortion grid. The main cause of the power oscillations is comprehensively demonstrated, optimised and examined with numerical studies and theoretically. Control parameters are accurately selected by the courtesies of optimisation function to minimise power oscillations. A fast and robust third-order sinusoidal signal integrator (TOSSI) extracts positive–negative sequence components for the calculation of the RCG. To provide a fast transient response and achieve almost current tracking errors at a zero level, proportional complex integral (PCI) current regulation controller is selected. Various case studies have been performed to show the validity and availability of the proposed entire system, including flexible control, optimisation, TOSSI and PCI.