  Context: Broadband optical constants of astrophysical ice analogues in the
infrared (IR) and terahertz (THz) ranges are required for modeling the dust
continuum emission and radiative transfer in dense and cold regions, where
thick icy mantles are formed on the surface of dust grains. Aims: In this
paper, the THz time-domain spectroscopy (TDS) and the Fourier-transform IR
spectroscopy (FTIR) are combined to study optical constants of CO and CO$_2$
ices in the broad THz-IR spectral range. Methods: The measured ices are grown
at cryogenic temperatures by gas deposition on a cold Si window. A method to
quantify the broadband THz-IR optical constants of ices is developed based on
the direct reconstruction of the complex refractive index of ices in the THz
range from the TDS data, and the use of the Kramers-Kronig relation in the IR
range for the reconstruction from the FTIR data. Uncertainties of the
Kramers-Kronig relation are eliminated by merging the THz and IR spectra. The
reconstructed THz-IR response is then analyzed using classical models of
complex dielectric permittivity. Results: The complex refractive index of CO
and CO$_2$ ices deposited at the temperature of $28$ K is obtained in the range
of 0.3--12.0 THz. Based on the measured dielectric constants, opacities of the
astrophysical dust with CO and CO$_2$ icy mantles are computed. Conclusions:
The developed method can be used for a model-independent reconstruction of
optical constants of various astrophysical ice analogs in a broad THz-IR range.
Such data can provide important benchmarks to interpret the broadband
observations from the existing and future ground-based facilities and space
telescopes. The reported results will be useful to model sources that show a
drastic molecular freeze-out, such as central regions of prestellar cores and
mid-planes of protoplanetary disks, as well as CO and CO$_2$ snow lines in
disks.
