Galaxy evolution through infrared and submillimeter spectroscopy: Measuring star formation and black hole accretion with JWST and ALMA