Modelling the cosmic spectral energy distribution and extragalactic background light over all time