One of the main design challenges in Wireless Sensor Networks (WSN) is to prolong the system lifetime, while achieving acceptable quality of service for applications. In WSN, each sensor node is battery powered and it is not convenient to recharge or replace the batteries in many cases, especially in remote and hostile environments. Due to the limited capabilities of sensor nodes, it is usually desirable that a WSN should be deployed with high density and thus redundancy can be exploited to increase the network’s lifetime. In this paper, we introduce an efficient lifetime optimization and self-stabilizing algorithm to enhance the lifetime of wireless sensor networks especially when the reliabilities of sensor nodes are expected to decrease due to use and wear-out effects. Our algorithm seeks to build resiliency by maintaining a necessary set of working nodes and replacing failed ones when needed. We provide some theoretical and simulation results, that fully demonstrate the usefulness of the proposed algorithm.