In this paper, an enhanced sparrow search algorithm (ESSA) is proposed to solve the optimal power flow (OPF) problem of power systems considering renewable energy systems. Two modifications were introduced to the basic SSA to overcome its weak global search capability. Elite reverse learning strategy for diversifying the population and mutation strategy of firefly algorithm (FA) to achieve a fast convergence rate. The effectiveness of the ESSA is analysed for two types of power systems: conventional power systems with only thermal power plants and modern power systems with thermal and renewable energy power plants. A multi-objective optimisation problem considering the operational cost of power plants and greenhouse gas (GHG) emissions was formulated with multiple power system variables and its operational equal and unequal constraints. The effectiveness of ESSA was verified on standard IEEE 14-bus and IEEE 30-bus test systems without RE plants and compared with the literature. In addition, a real-time Andhra Pradesh, an Indian power system with 14-bus is simulated with RE systems. In the 14-bus test system, the cost is reduced by 89.97 $/h, the losses are reduced by 4.106 MW, the voltage deviation is reduced by 0.1276 p. u., and GHG emissions are reduced by 8407.86 lb/MWh. In the 30-bus test system, the cost was reduced by 73.1 $/h, the losses were reduced by 3.962 MW, the voltage deviation was reduced by 0.00459 p. u., and GHG emissions were reduced by 8113 lb/MWh. On the other hand, in a real-time system, the cost is reduced by 114.41 $/h, the losses are reduced by 1.177 MW, the voltage deviation is reduced by 0.1116 p. u., and GHG emissions are reduced by 75560.13 lb/MWh. The obtained results confirm that the proposed ESSA outperforms the basic SSA and other competitive metaheuristics, namely the grasshopper optimisation algorithm (GOA), whale optimisation algorithm (WOA), and mothflame optimisation (MFO), to solve the OPF problem. However, embedding RE plants in the OPF problem has resulted in significant reductions in operating costs and GHG emissions, which are the need of the present world with rising fossil fuel costs and increasing global warming.