In the realm of electrical distribution, managing power quality is critical due to its significant impact on infrastructure and customer satisfaction. Addressing issues such as voltage sags and swells, along with current and voltage harmonics, is imperative. The innovative approach proposed in this paper centers on a dual-phase control strategy using a Universal Power Quality Conditioner that integrates series and parallel compensations to rectify these disturbances simultaneously. Our methodology introduces a hybrid control scheme that employs adaptive dynamic neural networks (ADNN), a sinusoidal tracking filter (STF), and a proportional-integral (PI) controller optimized via an improved krill herd (IKH) algorithm. The first phase utilizes the ADNN-based adaptive integrated estimator for quick and accurate disturbance detection and estimation. Subsequently, the second phase employs the STF, omitting the Low Pass Filter and employing a Phase Locking Loop to generate precise reference voltages and currents for the series and parallel active filters based on dynamic load and source conditions. This advanced control mechanism not only enhances system efficacy but also reduces the need for extensive computational resources. Furthermore, the performance of both series and parallel inverters is finely tuned through a PI controller optimized with the IKH algorithm, improving the DC link voltage regulation. Our extensive testing under various conditions, including voltage imbalances and harmonic disturbances, demonstrates the robustness of the proposed solution in both transient and steady-state scenarios.