The huge power requirements of future railways require the usage of energy-efficient strategies towards a more intelligent railway system. The usage of on-board energy storage systems enables better usage of the traction energy with a higher degree of freedom. In this article is proposed a top-level charging controller for the on-board and wayside railway energy storage systems. Its structure comprehends two processing levels: a real-time fuzzy logic controller for each energy storage system, and a genetic algorithm meta-heuristic, that remotely and automatically tune the fuzzy rules weight. As global results, the reduction of regenerated energy is 22.3% with the fuzzy logic controller. With the optimization strategy, this reduction can be further extended to 28.7%. The need for a smart railway framework is also discussed towards a realistic implementation of such charging strategy. Thus, with a high degree of flexibility, the efficiency of railway energy systems can be increased with the proposed framework.