Vehicle-to-Grid (V2G) technology and Naive Bayes optimization, which might help IoT devices, navigate grid dynamics. Electric vehicles (EVs) with bidirectional charging capability may provide grid assistance using their energy storage capacity. These cars can take and return energy from the grid using V2G technology, stabilizing the system. This paper proposes a unique technique to intelligently control energy flow between the grid and EVs using V2G technology and Naive Bayes optimization algorithms. Using previous data on energy consumption, grid circumstances, and vehicle charging behavior, the Naive Bayes algorithm makes real-time predictions and decisions. In IoT-enabled smart grids, this connection improves energy management efficiency and reliability. The implementation methods and experimental findings of the suggested strategy are discussed in the study. The system grid stability, energy usage, and grid dynamics management are also assessed. The results show that V2G technology and Naive Bayes optimization in IoT systems can intelligently navigate grid dynamics, creating a more sustainable and resilient energy infrastructure. To smart grid expertise and shows how V2G-enabled IoT devices may optimize energy distribution and ensure grid stability in the face of dynamic energy needs.