The reliability of the power supply for 5G base stations (BSs) is increasing. A large amount of BS backup energy storage (BES) remains underutilized. This study establishes a double-layer optimization distribution network (DN) considering BS clusters. An energy consumption characteristics and scheduling ability model of the BSs was established to address the differences in the characteristics of different traffic flows. A double-tier planning model for BS-joining grid market ancillary services is proposed. The upper-layer model addresses optimal tidal flow problems in DNs to minimize integrated operating costs, while the lower-layer model focuses on BES economic optimization. The double-layer model changes into a single-layer linear model using the Karush–Kuhn–Tucker (KKT) condition and the Big M method. Simulation validation using the IEEE-33 node DN proves that this approach can reduce DN operating costs, regulate voltage fluctuations, and guarantee economical and safe DN operation.