Driven by a broad range of applications, the Computational Intelligence research community has recently put a growing interest on the emergent technology of Wireless Sensor Networks (WSNs). Due to their distributed structure, WSNs pose several technical challenges caused by local failures, network issues and severely constrained hardware resources. Nevertheless, the possibility to perform an online optimization within WSNs is appealing since it might lead the path to advanced network features like intelligent sensing, distributed modelling, self-optimizing protocols, anomaly detection, etc. just to name a few. In this paper we present DOWSN, a novel Distributed Optimization framework for WSNs. Based on an island model, DOWSN is characterized by a peer-to-peer infrastructure in which each node executes an optimization process and shares pieces of information, i.e. local achievements, with its neighbors. Preliminary experiments show that DOWSN is able to efficiently exploit the communication capabilities and the inherently parallel nature of WSNs, thus finding optimal solutions fast and reliably.