In this research paper, the integration of Vehicle-to-Grid (V2G) technology within a microgrid framework, emphasizing its role in enhancing grid stability through renewable energy optimization, was explored. The increasing penetration of electric vehicles (EVs) and renewable energy sources, such as photovoltaic (PV) farms and wind farms, presents both opportunities and challenges for modern power grids. To address these, we developed a comprehensive model simulating a 24-hour operation of a microgrid incorporating an 8 MW PV farm, a 4.5 MW wind farm, and a diesel generator. The model also includes residential and industrial loads, along with 100 EVs equipped with 40 kW batteries, capable of contributing 4 MW back to the grid. The simulation, conducted in MATLAB/Simulink, examines the dynamic interactions between these components under various conditions, including partial shading effects on the PV farm and wind farm tripping due to high wind speeds. The results demonstrate the effectiveness of V2G technology in balancing power generation and consumption, particularly during peak load periods. By optimizing the timing of EV charging and discharging, we show a significant reduction in the dependency on nonrenewable energy sources, thereby enhancing the overall stability and efficiency of the microgrid. The findings highlight the potential of V2G systems to serve as a crucial element in future energy systems, facilitating the seamless integration of intermittent renewable energy sources while supporting grid frequency regulation and reducing greenhouse gas emissions. This study provides valuable insights for optimizing microgrid operations and underscores the importance of V2G technology in achieving sustainable energy goals.