Functional integral approach to time-dependent heat exchange in open quantum systems: general method and applications