A solid state electronic nanodevice is an intrinsically open quantum system, exchanging both energy with the host material and carriers with connected reservoirs. Its out-of-equilibrium behavior is determined by a non-trivial interplay between electronic dissipation and decoherence induced by inelastic processes within the device, and the coupling of the latter to metallic electrodes. We propose a unified description, based on the density matrix formalism, that accounts for both these aspects, enabling to predict various steady-state as well as ultrafast nonequilibrium phenomena, nowadays experimentally accessible. More specifically, we derive a generalized density-matrix equation, particularly suitable for the design and optimization of a wide class of electronic and optoelectronic quantum devices. The power and flexibility of this approach is demonstrated with the application to a photoexcited triple-barrier nanodevice.