We propose an approach to self-optimizing wireless sensor networks (WSNs) which are able to find, in a fully distributed way, a solution to a coverage and lifetime optimization problem. The proposed approach is based on three components: (a) a multi-agent, social-like interpreted system, where the modeling of agents, discrete space, and time is provided by a 2-dimensional second-order cellular automata, (b) the interaction between agents is described in terms of the spatial prisoner’s dilemma game, and (c) a local evolutionary mechanism of competition between agents exists. Nodes of a WSN graph created for a given deployment of WSN in the monitored area are considered agents of a multi-agent system that collectively make decisions to turn on or turn off their batteries. Agents are controlled by cellular automata (CA)-based players participating in a variant of the spatial prisoner’s dilemma iterated game. We propose for players participating in this game a local payoff function that incorporates issues of area coverage and sensors energy spending. Rewards obtained by agent players depend not only on their personal decisions but also on their neighbor’s decisions. Agents act in such a way to maximize their own rewards, which results in achieving by them a solution corresponding to the Nash equilibrium point. We show that the system is self-optimizing, i.e., can optimize in a distributed way global criteria related to WSN and not known for agents, provide a balance between requested coverage and spending energy, and result in expanding the WSN lifetime. The solutions proposed by the multi-agent system fulfill the Pareto optimality principles, and the desired quality of solutions can be controlled by user-defined parameters. The proposed approach is validated by a number of experimental results.