Modelling the spectral energy distribution of ULIRGs. II. The energetic environment and the dense interstellar medium