Detecting anomalies is an important challenge for intrusion detection and fault diagnosis in wireless sensor networks (WSNs). To address the problem of outlier detection in wireless sensor networks, in this paper we present a PCA-based centralized approach and a DPCA-based distributed energy-efficient approach for detecting outliers in sensed data in a WSN. The outliers in sensed data can be caused due to compromised or malfunctioning nodes. In the distributed approach, we use distributed principal component analysis (DPCA) and fixed-width clustering (FWC) in order to establish a global normal pattern and to detect outlier. The process of establishing the global normal pattern is distributed among all sensor nodes. We also use weighted coefficients and a forgetting curve to periodically update the established normal profile. We demonstrate that the proposed distributed approach achieves comparable accuracy compared to the centralized approach, while the communication overhead in the network and energy consumption is significantly reduced.