An important issue in the three-dimensional (3D) wireless sensor networks (WSNs) is sensor energy optimization. To alleviate this issue, we introduce a new 3D spherical network structure model, and by combining the original energy consumption model to construct a new method to determine the optimal number of clusters and balance the total energy consumption. Since the different sizes of the clusters are generated by traditional hierarchical clustering, it causes unbalanced energy consumption in the network. To alleviate this problem, we adopt an improved dynamic hierarchical clustering method and implement two strategies that include the following three contributions: the introduction of the distance similarity index to get a better clustering, a double cluster head (CH) strategy to reduce the load of a cluster head in a large cluster, and a node dormancy mechanism to balance the energy consumption of the network. In addition, we also propose the optimal cluster-head function to select the CH of each cluster in each round, and the optimal cluster-head function is constructed based on the residual energy and positions of the nodes. Finally, to optimize the CH election strategy, several parameters of the optimal cluster-head function are determined according to the network structure. The simulation results show that our routing protocol is more robust compared with four other protocols, which is of great significance for the application in 3D environment monitoring.