Using the Planck 2015 data release (PR2) temperature maps, we separate Galactic thermal dust emission from cosmic infrared background (CIB) anisotropies. For this purpose, we implement a specifically tailored component-separation method, the so-called generalized needlet internal linear combination (GNILC) method, which uses spatial information (the angular powerspectra) to disentangle the Galactic dust emission and CIB anisotropies. We produce significantly improved all-sky maps of Planck thermal dust emission, with reduced CIB contamination, at 353, 545, and 857 GHz. By reducing the CIB contamination of the thermal dust maps, we provide more accurate estimates of the local dust temperature and dust spectral index over the sky with reduced dispersion, especially at high Galactic latitudes above b = ±20°. We find that the dust temperature is T = (19.4 ± 1.3) K and the dust spectral index is β = 1.6 ± 0.1 averaged over the whole sky, while T = (19.4 ± 1.5) K and β = 1.6 ± 0.2 on 21% of the sky at high latitudes. Moreover, subtracting the new CIB-removed thermal dust maps from the CMB-removed Planck maps gives access to the CIB anisotropies over 60% of the sky at Galactic latitudes |b| > 20°. Because they are a significant improvement over previous Planck products, the GNILC maps are recommended for thermal dust science. The new CIB maps can be regarded as indirect tracers of the dark matter and they are recommended for exploring cross-correlations with lensing and large-scale structure optical surveys. The reconstructed GNILC thermal dust and CIB maps are delivered as Planck products.