This study presents an optimal power flow (OPF) method utilizing the Whale Optimization Algorithm (WOA) for integrating renewable energy sources (RES) such as solar and wind into electrical power systems while minimizing generation costs. The proposed WOA is evaluated against traditional approaches like genetic algorithms and particle swarm optimization, demonstrating its superior performance in terms of convergence and diversity of solutions. The methodology is applied to the IEEE-30 system, showcasing its effectiveness in addressing the complexities of power flow management with RES.