Given the increasing worldwide energy demand and the growing environmental apprehension regarding the utilization of fossil fuels in power systems, it is critical to implement viable alternatives to resolve this issue. Subsequently, renewable energy sources (RESs), which generate minimal pollution, have become the predominant choice for fulfilling energy requirements. By employing an innovative problem formulation approach, this study proposes reducing costs to attain the most economical overall cost for the grid. Concurrently, there has been a shift in the transportation industry from traditional vehicles propelled by fossil fuels to those that are electrified. Plug-in electric vehicles (PEVs) and plug-in hybrid electric vehicles (PHEVs) have emerged as prominent alternatives and are being embraced at an accelerated rate. By linking to the power grid and utilizing vehicle-to-grid (V2G) and grid-to-vehicle (G2V) innovations, these vehicles can either receive or return energy to the grid. Microgrids (MGs), which are an emerging concept in power systems, seek to optimize the performance of electric vehicles (EVs) through their integration with intelligent infrastructure and to encourage the incorporation of renewable energy sources (RESs). To facilitate the integration of PEVs into the network, the vehicle-to-grid (V2G) capacity is effectively utilized to reduce operational costs. This underscores the criticality of the resource management problem at MG. Unscented transformation (UT), an efficient stochastic programming technique, is utilized in this study's optimization framework to optimize the energy management of MGs (including PEVs and RESs) for the upcoming day. Approaching this issue as a stochastic optimization problem with the sole objective of minimizing the overall operational cost. The problem at hand is resolved by utilizing the modified water strider (MWS) algorithm, an efficient approach inspired by nature. Its efficacy is assessed through a comparative analysis with other documented techniques.