Theory of irreversible processes in nonequilibrium quantum systems. I. General formalism