With the progress of low-power research on real-time systems, the estimation and analysis of energy consumption of real-time systems becomes a hot topic. Process Algebra is a formal method fit for analyzing the functional properties of real-time systems, but it can not analyze the energy consumption properties. This paper proposes a formal method support for modeling and analyzing energy consumption of real-time software. Resource Timed Communicating Sequential Process (RTCSP) is proposed in this paper can handle it efficiently by extending resource information on Timed Communicating Sequential Process (TCSP). In this paper, the power consumption of instructions in real-time systems is mapped into the resource of RTCSP, the energy consumption of real-time software can be modeled and optimized by using RTCSP, the optimal path algorithm is proposed to calculate the minimum energy consumption reachability path of real-time systems. This formal method improves the accuracy and efficiency of energy calculation, the calculation results can be used to quantitatively analyze and optimize the energy consumption of real-time systems.