Effective method to compute vibrationally resolved optical spectra of large molecules at finite temperature in the gas phase and in solution