This paper introduces a hybrid algorithm that combines machine learning and modified teaching learning-based optimization (TLBO) for enhancing smart city communication and energy management. The primary objective is to optimize the modified systems, which face challenges due to their high population density. The proposed algorithm integrates the strengths of machine learning techniques, more specifically, the long short-term memory (LSTM) technique, with teaching learning-based optimization algorithms. To achieve optimization, the algorithm learns from historical data on energy consumption and communication patterns specific to the modeled system. By leveraging these insights, it can predict future energy consumption and communication patterns accurately. Additionally, the algorithm incorporates a modified teaching learning-based optimization approach inspired by the teaching and learning process in classrooms. It adjusts the system parameters based on feedback received from the system, thereby optimizing both energy consumption and communication systems. The effectiveness of the proposed algorithm is evaluated through a case study conducted on the test system, where historical data on energy consumption and communication patterns are analyzed. The results demonstrate that the algorithm efficiently optimizes the communication and energy management systems, leading to substantial energy savings and improved communication efficiency within the test system. In conclusion, this study presents a hybrid machine learning and modified teaching learning-based optimization algorithm that effectively addresses the communication and energy management challenges in the test system. Moreover, this algorithm holds the potential for application in various smart city domains beyond the test system. The findings of this research contribute to the advancement of smart city technologies and offer valuable insights into reducing energy consumption in densely populated urban areas.