This research addresses the imperative need for innovative approaches to harness renewable resources while ensuring grid stability amidst global electricity demand. The proposed optimization methodology, centered on machine learning, harmonizes the intermittent output of Wind-PV systems with dynamic grid requirements. Leveraging historical meteorological data, energy trends, and real-time demand, the study employs ensemble learning, specifically the CNN (Convolutional Neural Network) algorithm, for accurate forecasting of PMSG-based (Permanent Magnet Synchronous Generator) Wind-PV system output. The two-tiered optimization approach involves short-term prediction using the CNN model and real-time correction through a genetic algorithm, enhancing the Capacity Utilization factor from 73% to 92% and reducing mean absolute error from 8% to 4.5%. This method not only anticipates energy fluctuations efficiently but also contributes to grid stability and decreased reliance on nonrenewable sources. Comparative analyses demonstrate the superiority of the machine learning-based approach in terms of accuracy and adaptability over traditional control methods.