This paper proposes an integrated framework to improve microgrid energy management through the integration of renewable energy sources, electric vehicles, and adaptive demand response strategies. An optimization strategy based on machine learning employs a support vector machine for forecasting renewable energy, aiming to enhance the scheduling of green energy utilization, demand response, and the optimal charging and discharging of battery energy storage for dynamic energy balancing, thereby improving microgrid efficiency. The study utilized data from a grid-connected microgrid including 46 home participants, five of homes were equipped with batteries, wind turbines, photovoltaic panels, and electric vehicle charging stations. It examined scenarios involving energy transactions with and without the participation of electric vehicle batteries. The framework optimizes each microgrid component: renewable energy sources are predicted with high accuracy (R2 = 0.97), shared battery energy storage system reduces peak demand costs by 30.5%, and electrical vehicle integration lowers grid dependence by 29% through surplus energy transactions and realized cost saving of £445. Adaptive demand response mechanisms, including real-time pricing and time-of-use tariffs, further enhance economic and environmental sustainability. Each microgrid component is dynamically optimized to maximize efficiency and flexibility by mixed integer linear programing optimization algorithm. Electric vehicles engage in energy trading via bidirectional transactions, diminishing dependence on grid power and enhancing energy efficiency. Simultaneously, demand response programs implement adaptable pricing structures to manage consumption behaviors and optimize economic advantages. This research adds to the development of cost-effective and scalable microgrid systems, aiding reducing grid dependency and maximize renewable energy usage.