Network lifetime and localization are critical design factors for a number of wireless sensor network (WSN) applications. These networks may be randomly deployed and left unattended for prolonged periods of time. This means that node localization is performed after network deployment, and there is a need to develop mechanisms to extend the network lifetime since sensor nodes are usually constrained battery-powered devices, and replacing them can be costly or sometimes impossible, e.g., in hostile environments. To this end, this work proposes the energy-aware connected k-neighborhood (ECKN): a joint position estimation, packet routing, and sleep scheduling mechanism. To the best of our knowledge, there is a lack of such integrated solutions to WSNs. The proposed localization algorithm performs trilateration using the positions of a mobile sink and already-localized neighbor nodes in order to estimate the positions of sensor nodes. A routing protocol is also introduced, and it is based on the well-known greedy geographic forwarding (GGF). Similarly to GGF, the proposed protocol takes into consideration the positions of neighbors to decide the best forwarding node. However, it also considers node residual energy in order to guarantee the forwarding node will deliver the packet. A sleep scheduler is also introduced in order to extend the network lifetime. It is based on the connected k-neighborhood (CKN), which aids in the decision of which nodes switch to sleep mode while keeping the network connected. An extensive set of performance evaluation experiments was conducted and results show that ECKN not only extends the network lifetime and localizes nodes, but it does so while sustaining the acceptable packet delivery ratio and reducing network overhead.