We present a holistic framework for energy management in sensor
networks. Our framework is based on a model-driven approach that
attempts to (a) establish functional relationships across different
modules of the software stack and the interrelated parameters based on
empirical data, (b) use the maximum sensor value and time-synchronization errors acceptable by the users of the sensor network application as input to establish minimum quality of service requirements, and (c) do cross-layer optimization of the parameter values of all the software modules within the node's application stack to minimize total energy consumption for each sensor node. We explore the trade-offs of the design space by using a non-trivial application that includes sensing, time synchronization and routing modules, in multiple different testbeds, and with different routing software modules. We show that when using our framework, we can provide average energy savings from 38\% to 62\% when compared with the software modules default values, and from 11\% to 33\% when compared with the state-of-the-art AODC duty-cycle optimization scheme while still maintaining quality of service both in terms of the expected sensing and time synchronization errors. We further show that we can slightly decrease latency (1.5%-3.5%) and slightly improve reliability (1%-3%).