• Proposing analytical method for global optimal strategy of battery in energy system. • Reducing calculation burden of battery scheduling in energy systems. • Sensitivity analysis of energy system performance in optimal operation mode. This paper presents an analytical approach for the optimal operation of battery-integrated energy systems (BIES). Energy profile sectionalizing, achieved through the offline studies, is proposed in this paper as a framework for optimal energy dispatch in BIES, and an online strategy is then explained to control the energy system optimally. In this paper, a general framework of the battery control is addressed with considering battery characteristics and system electricity tariffs to make the proposed method applicable to real cases. Applying the proposed method to BIES shows great advantages in optimal battery scheduling as it guarantees to achieve the global optimal operation of the battery considering its actual parameters compared to the previous studies focusing on the use of optimization methods whose outputs are near-optimal solutions. Real load profile and electricity prices are used to test the proposed approach through a developed code in MATLAB software. The results show that the cost of the energy system and calculation burden of achieving optimal results are decreased compared with using the genetic algorithm (GA) and harmony search algorithm (HSA).