Wireless Sensor Networks (WSNs) have become ubiquitous across various domains, from household applications to industrial grounds, and critical areas like emergency response and environmental monitoring. While numerous optimization techniques have emerged in the literature to enhance network performance by strategically allocating sensor nodes, most studies in this field rely on heuristic methods. Designing the topology of WSNs is crucial for optimizing node energy consumption, connectivity, and coverage area. In this work, two methodologies are proposed to minimize the overall energy consumption of the network. The first is an exact method using a Mixed Integer Linear Programming (MILP) model. The second is an optimization method based on genetic algorithms (GAs). In the computational experiments, instances were generated based on grid-like networks, some of which assuming highly irregular topologies. The results have shown that the exact approach found optimal solutions for some instances, up to five thousand nodes. In contrast, the GA obtained high-quality solutions for instances with more than 18 thousand nodes in reasonable computational times.