Wireless nanosensor networks (WNSNs) consist of nanosized communicating devices, which can detect and measure new types of events at the nanoscale. WNSNs are the enabling technology for unique applications such as intrabody drug delivery systems or surveillance networks for chemical attack prevention. One of the major bottlenecks in WNSNs is posed by the very limited energy that can be stored in a nanosensor mote in contrast to the energy that is required by the device to communicate. Recently, novel energy harvesting mechanisms have been proposed to replenish the energy stored in nanodevices. With these mechanisms, WNSNs can overcome their energy bottleneck and even have infinite lifetime (perpetual WNSNs), provided that the energy harvesting and consumption processes are jointly designed. In this paper, an energy model for self-powered nanosensor motes is developed, which successfully captures the correlation between the energy harvesting and the energy consumption processes. The energy harvesting process is realized by means of a piezoelectric nanogenerator, for which a new circuital model is developed that can accurately reproduce existing experimental data. The energy consumption process is due to the communication among nanosensor motes in the terahertz band (0.1-10 THz). The proposed energy model captures the dynamic network behavior by means of a probabilistic analysis of the total network traffic and the multiuser interference. A mathematical framework is developed to obtain the probability distribution of the nanosensor mote energy and to investigate the end-to-end successful packet delivery probability, the end-to-end packet delay, and the achievable throughput of WNSNs. Nanosensor motes have not been built yet and, thus, the development of an analytical energy model is a fundamental step toward the design of WNSNs architectures and protocols.