Localization is an essential task in Wireless Sensor Networks (WSN) for various use cases such as target tracking and object monitoring. Anchor nodes play a critical role in this task since they can find their location via GPS signals or manual setup mechanisms and help other nodes in the network determine their locations. Therefore, the optimal placement of anchor nodes in a WSN is of particular interest for reducing the energy consumption while yielding better accuracy at finding locations of the nodes. In this paper, we propose a novel approach for finding the optimal number of anchor nodes and an optimal placement strategy of them in a large-scale WSN, based on the output of Grey Wolf Optimization (GWO) and Particle Swarm Optimization (PSO) methods. As an initial step in this approach, the virtual localization process is executed over a virtual coordinate system in order to optimize the efficiency of the localization process. GWO and PSO methods are compared with a coverage-based analytical method and machine learning approaches such as Support Vector Machine (SVM) regression and Multiple Regression. The simulations we run with different numbers of nodes in a WSN and different communication ranges of nodes demonstrate that the proposed approaches are superior for minimizing the localization errors while reducing the number of anchor nodes.