Nowadays, Wireless Sensor Networks (WSNs) are significantly applied in engineering and scientific research. WSNs consist of a group of distributed space sensors that track the environment's physical conditions and control the collected data at one central location. Examples of these sensors' applications are smart cities, transport, volcano surveillance and environmental activity, earthquake monitoring, medicine, post-disaster response, and military control. Wireless sensor networks have a lot of research issues like access to the media, implementation, time synchronization, network security and localization of the nodes. One of the most critical problems in this network research is the optimum position of the sensors to have access to maximum coverage and increase network life span to decrease maintenance costs, develop and manage the network. One of the main causes of the failure in these networks is running out of sensor battery and replacing them which impose high costs to maintenance and managing of the network. In order to solve the issues related to optimization and localization, researchers have focused on the algorithms like Swarm Intelligence (SI), because they enable us to solve complicated issues of optimization and NP-Hard issues to solve optimization. However, most of these algorithms are specialized for a purpose or a special program, and the majority of the solutions are not compatible with most of the wireless network sensors. The DV-Hop is one of the most popular node algorithms. But the main problem of the DV-Hop is the possibility of error in calculating the assessed distance between the unknown node and the nodes of anchor. Therefore, minimizing this error is the key to improve this algorithm. To reduce the problem of high localization error, two meta-heuristic algorithms have been proposed based on a combination. In this paper, a new optimization method based on a combination of Krill Herd Algorithm (KHA) and Particle Swarm Optimization (PSO) called KHAPSO is suggested to improve DV-Hop. Simulation results in MATLAB 2016 show that the KHAPSO model has a lower mean error compared to the DV-Hop, DV-Hop-KHA and DV-Hop-PSO models. Also, energy consumption in the KHAPSO model is less in comparison to the other models. The KHAPSO model with 400 unknown nodes and 30 anchor nodes was able to reduce energy consumption by about 35% and at the same time 27% reduction in Average Localization Error (ALE) compared to DV-Hop.