Many-body Green’s function theory for electron-phonon interactions