The proposed optimal energy management system balances the energy flows among the energy consumption by accelerating trains, energy production from decelerating trains, energy from wind and solar photovoltaic (PV) energy systems, energy storage systems, and the energy exchange with a traditional electrical grid. In this paper, an AC optimal power flow (AC-OPF) problem is formulated by optimizing the total cost of operation of a railroad electrical system. The railroad system considered in this paper is composed of renewable energy resources such as wind and solar PV systems, regenerative braking capabilities, and hybrid energy storage systems. The hybrid energy storage systems include storage batteries and supercapacitors. The uncertainties associated with wind and solar PV powers are handled using probability distribution functions. The proposed optimization problem is solved using the differential evolution algorithm (DEA). The simulation results show the suitability and effectiveness of proposed approach.