The integration of renewable energy systems in port facilities is essential for achieving sustainable and environmentally friendly operations. This paper presents the implementation of an Optimal Energy Hub approach in smart green ports, with a focus on the case study of Egypt and the Middle East Oil Transmission & Pipelines Company (MIDTAP) company. The study explores the integration of photovoltaic (PV) and wind energy systems within the port's operations. Machine learning methodologies are utilized to optimize energy management and decision-making processes in the port. The proposed approach leverages historical data, weather forecasts, and real-time energy demand to predict and optimize the utilization of PV and wind energy resources. By utilizing machine learning techniques, the energy hub can efficiently balance energy supply and demand, ensuring optimal utilization of renewable sources while minimizing reliance on conventional energy sources. Furthermore, this paper discusses a scenario of increasing load and renewable energy generation in the port facility. A comprehensive energy flow-based mixed integer linear programming (MILP)-based optimization framework implemented in MATLAB is presented. This framework aims to minimize electricity consumption costs while providing considerable flexibility and adaptability to accommodate the changing energy landscape. The results of the study provide valuable insights into the implementation of sustainable energy solutions in smart green ports, specifically in the context of Egypt and the MIDTAP company. The integration of PV and wind energy systems, along with the proposed MILP-based optimization framework, offers a practical and efficient approach to minimize electricity consumption costs and reduce the carbon footprint of port operations. The findings demonstrate the flexibility and adaptability of the Optimal Energy Hub approach in accommodating increasing loads and renewable energy generation. The research findings encourage the adoption of similar energy hub approaches in other port facilities, contributing to the global transition towards greener and more sustainable practices. The utilization of machine learning methodologies and MILP-based optimization frameworks in smart green ports can facilitate cost-effective and environmentally friendly energy management, promoting a more sustainable future for port operations. Several scenarios were used to show how the proposed notion was perceived. The primary objective is to maximize the use of renewable energy sources while reducing expenses and emissions. The MIDTAP Company evaluated the effects of adding more renewable energy systems in smart green ports through a study involving six scenarios. Additionally, MIDTAP Company conducted research with six scenarios to assess the impact of increasing the number of renewable energy systems in smart green ports. In these scenarios, the renewable energy systems (PV + Wind) are increased by 10%, 20%, 30%, and 40%, while the load is increased by 25% and 50%. The primary objective of these scenarios is to maximize the use of renewable energy sources while reducing expenses and emissions, and the results provide valuable insights into the potential benefits and challenges of scaling up renewable energy systems in smart green ports. The significance of grid connectivity and sustainable energy solutions for smart green ports was also emphasized by the study. The findings show how economical and sustainable energy solutions may be achieved in smart green ports through the application of machine learning and optimization based on MILP. The selection of a 40% increase in renewable energy systems (PV + Wind) in the sixth scenario, which aims to explore the potential for further scaling up renewable energy infrastructure within the MIDTAP port, is based on the available area in MIDTAP. Considering the spatial limitations and resource availability of the port, careful assessment and planning are crucial to determine the optimal capacity for renewable energy systems. By selecting a 40% increase, the study takes into account the available area within MIDTAP and the potential for accommodating additional renewable energy installations. This approach ensures that the scenario aligns with the port's physical constraints while still pushing the boundaries of renewable energy integration. Evaluating this scenario provides insights into the feasibility and benefits of leveraging a larger share of renewable energy sources within the port, ultimately contributing to its sustainable and environmentally friendly operations.