The Interstellar Medium of Galaxies and AGN since Cosmic Dawn