Reactive power compensation is essential in hybrid grid-connected systems because power electronic inverters utilized for supplying DC energy into the grid causes a reduction in the overall power factor of the power systems. Due to the ability to provide a reliable and efficient power supply to remote and off-grid areas, hybrid power systems are growing in popularity. It can provide greater opportunities for operational growth by combining economic and technology advancement. To meet the demand for electrical energy in both regular and critical situations, operators must be in charge of the power systems reliable and secure operation. The primary objective of the work is to control the reactive power flow in a grid-connected hybrid renewable energy system (PV-wind-battery). The power quality problems that these systems frequently experience include voltage sags, harmonics, and flicker. A FACTS device Unified Power Quality controller (UPQC) with a Genetic Algorithm based PI controller is suggested to handle these power quality issues. In order to improve the performance of the power system, the proposed optimization approaches are used to tune the UPQC in a multiline transmission system. The model was developed with the help of the MATLAB/Simulink work framework.