In today's ever -evolving power generation landscape, a transformative shift is unfolding, propelled by the rise of renewable energy microgrids, revolutionizing conventional electricity generation. The novel idea presented in this work addresses the intricate control and optimization challenges inherent in hybrid AC/DC microgrids that integrate various distributed generators, energy storage technologies, loads, converters, and inverters. To overcome these complexities, we introduce a novel approach centered on a condition -based supertwisting sliding mode control (CBSTSMC). This control strategy offers several advantages, including chatter -free operation and enhanced robustness. Notably, the CBSTSMC addresses the wind-up phenomenon during control signal saturation, a common issue in microgrid control, thereby contributing to improved system stability. Furthermore, we have also focused on various aspects of the microgrid including the use of artificial neural networks for maximum power point tracking of wind and PV systems, an energy management system, and Grey Wolf optimization for gain tuning of controllers. The system's stability is rigorously validated through Lyapunov analysis. To validate real-time control effectiveness, the proposed approach undergoes experimental verification using hardware -in -loop implementation, employing a C2000 Delfino microcontroller, in tandem with simulation in MATLAB/Simulink. The CBSTSMC approach is also compared with sliding mode control and super twisting sliding mode control.