Modelling the operation of energy storage systems such as batteries in an energy model is challenging as it requires estimation of current and future imbalances between supply and demand and the value of energy stored and later returned to the system. Here, an approach is developed which optimally prioritises the provision of stored energy to the system according to a specified criterion such as time-of-use tariff. At this stage, the model assumes perfect knowledge of future supply and demand as well as a hierarchy of utility to the system operator. Such an operator would specify a ranked list of times of need from the energy storage. The model will then allocate available energy from earlier times while reserving necessary space in the available storage. By progressing through the times of need in ranked order, the model ensures best optimum use of the stored energy. The results show that the proposed method is very robust and can calculate reliably the potential of an energy storage system in any energy model based on time steps of balancing generation and demand with the mediation of storage.