With the development of various applications of wireless sensor networks, they have been widely used in different areas. These networks are established autonomously and easily in most environments without any infrastructure and collect information of environment phenomenon for proper performance and analysis of events and transmit them to the base stations. The wireless sensor networks are comprised of various sensor nodes that play the role of the sensor node and the relay node in relationship with each other. On the other hand, the lack of infrastructure in these networks constrains the sources such that the nodes are supplied by a battery of limited energy. Considering the establishment of the network in impassable areas, it is not possible to recharge or change the batteries. Thus, energy saving in these networks is an essential challenge. Considering that the energy consumption rate while sensing information and receiving information packets from another node is constant, the sensor nodes consume maximum energy while performing data transmission. Therefore, the routing methods try to reduce energy consumption based on organized approaches. One of the promising solutions for reducing energy consumption in wireless sensor networks is to cluster the nodes and select the cluster head based on the information transmission parameters such that the average energy consumption of the nodes is reduced and the network lifetime is increased. Thus, in this study, a novel optimization approach has been presented for clustering the wireless sensor networks using the multiobjective genetic algorithm and the gravitational search algorithm. The multiobjective genetic algorithm based on reducing the intracluster distances and reducing the energy consumption of the cluster nodes is used to select the cluster head, and the nearly optimal routing based on the gravitational search algorithm is used to transfer information between the cluster head nodes and the sink node. The implementation results show that considering the capabilities of the multiobjective genetic algorithm and the gravitational search algorithm, the proposed method has improved energy consumption, efficiency, data delivery rate, and information packet transmission rate compared to the previous methods.