We use a relationship between response and correlation function in nonequilibrium systems to establish a connection between the heat production and the deviations from the equilibrium fluctuation-dissipation theorem. This scheme extends the Harada-Sasa formulation [Phys. Rev. Lett. 95, 130602 (2005)], obtained for Langevin equations in steady states, as it also holds for transient regimes and for discrete jump processes involving small entropic changes. Moreover, a general formulation includes two times and the new concepts of two-time work, kinetic energy, and of a two-time heat exchange that can be related to a nonequilibrium effective temperature. Numerical simulations of a chain of anharmonic oscillators and of a model for a molecular motor driven by ATP hydrolysis illustrate these points.