Edge data centres (EDCs) have been widely developed in these years to supply delay-sensitive computing services, which impose prohibitive increasing electricity costs for EDC operators. This paper develops a new spatiotemporal reallocation (STR) method for energy management in EDCs. This method uses spare resources, including servers and energy storage systems (ESSs) within EDCs to reduce energy costs based on both spatial and temporal features of spare resources. This solution: 1) reallocates flexible workload between EDCs within one cluster; and 2) coordinates electricity load of data processing, ESSs and distributed energy resources (DERs) within one EDC cluster to gain benefits from flexible electricity tariffs. In addition, this paper the first time develops a Bit-Watt transformation to simplify the STR method and represent the relation between data workload and electricity consumption of EDCs. The case studies justified the developed STR method delivers satisfied costs reduction with robustness. The STR method fully utilized both spatial and temporal features of spare resources in EDCs to gain benefits from 1) the varying electricity tariffs, and 2) maximumly consuming the DER generation.