In this work, an online energy management strategy for mild hybrid electric vehicles is developed to minimize the fuel consumption while simultaneously preventing battery overheating. Since mild hybrids are typically equipped with a passively cooled battery pack, the energy management strategy design needs to keep the battery temperature below an upper limit, preventing accelerated aging and thermal runaway. To address this issue, the equivalent consumption minimization strategy (ECMS) approach is extended to develop a real-time capable controller, termed thermal ECMS (Th-ECMS), that is sensitive to the thermal dynamics of the battery and that can enforce constraints on its temperature. The rationale for our formulation is based on Pontryagin's minimum principle from optimal control theory. The online Th-ECMS is developed on the basis of the offline version of Th-ECMS, introduced in a previous work. Exploiting the a priori knowledge of the driving mission, the offline Th-ECMS calibrates the equivalence factors and obtains the optimal solution, which is compared with the globally optimal dynamic programming solution. This offline calibration method is run on a large number of driving missions and the collected data is used to train a feed-forward neural network that estimates optimal equivalence factors as functions of the battery state of charge, battery temperature, and distance yet to travel. The trained network is then used to populate two lookup tables mapping the equivalence factors, and implementable on the vehicle electronic control unit. Finally, the online Th-ECMS obtains the equivalence factors through the look-up tables in realtime. The online strategy was tested in four different driving missions, achieving a fuel economy remarkably similar to the optimal solution and successfully avoiding battery overheating.