Microgrids, characterized by their ability to work individually or in combination with the main power system, play a pivotal role in addressing the growing demand for reliable and sustainable energy solutions. This work concentrates on the integration of sustainable energy sources, specifically photovoltaic (PV), and wind generation and a battery storage system within a microgrid framework. Additionally, a power flow control strategy is implemented to enhance the dynamic behaviour and stability of the microgrid. The proportional-integral (PI) controller is a fundamental component in regulating the microgrid's power flow, ensuring optimal performance under varying operating conditions. However, tuning the PI controller parameters is a difficult task because of the dynamic and nonlinear nature of renewable energy sources. In this work, the application of the Enhanced Randomized Harris Hawk Optimization (HHO) to fine-tune the PI controller is proposed, using the algorithm's ability to mimic the hunting behaviour of hawks in finding optimal solutions. The PV-Wind-Battery microgrid system is modelled, and the proposed algorithm is employed to optimize the PI controller parameters for efficient energy management. The ERHHO algorithm's exploration-exploitation balance is harnessed to navigate the complex solution space and converge to optimal PI controller settings, thereby enhancing the microgrid's stability and performance. The study evaluates the effectiveness of the proposed Enhanced Randomized Harris Hawk Optimization-based PI controller tuning through comprehensive simulations. Performance metrics such as transient response, overshoot, settling time, and steady-state error are analysed to validate the robustness and efficiency of the proposed method. The outcomes of this research contribute to the advancement of microgrid control strategies, offering a novel approach to PI controller tuning in the context of diverse renewable energy sources. The integration of the Harris Hawk Optimization algorithm provides a promising avenue for enhancing the operational efficiency and reliability of microgrids, paving the way for sustainable and resilient energy systems in the aspect of growing energy landscapes.