We present a CO and atomic fine-structure line-luminosity function analysis using the ALMA Spectroscopic Survey (ASPECS) in the Hubble Ultra Deep Field. ASPECS consists of two spatially overlapping mosaics that cover the entire ALMA 3 mm and 1.2 mm bands. We combine the results of a line-candidate search of the 1.2 mm data cube with those previously obtained from the 3 mm cube. Our analysis shows that ∼80% of the line flux observed at 3 mm arises from CO(2-1) or CO(3-2) emitters at z = 1-3 ("cosmic noon"). At 1.2 mm, more than half of the line flux arises from intermediate-J CO transitions (J up = 3-6); ∼12% from neutral carbon lines; and <1% from singly ionized carbon, [C ii]. This implies that future [C ii] intensity mapping surveys in the epoch of reionization will need to account for a highly significant CO foreground. The CO luminosity functions probed at 1.2 mm show a decrease in the number density at a given line luminosity (in units of L′) at increasing J up and redshift. Comparisons between the CO luminosity functions for different CO transitions at a fixed redshift reveal subthermal conditions on average in galaxies up to z ∼ 4. In addition, the comparison of the CO luminosity functions for the same transition at different redshifts reveals that the evolution is not driven by excitation. The cosmic density of molecular gas in galaxies, ρ H2, shows a redshift evolution with an increase from high redshift up to z ∼ 1.5 followed by a factor ∼6 drop down to the present day. This is in qualitative agreement with the evolution of the cosmic star formation rate density, suggesting that the molecular gas depletion time is approximately constant with redshift, after averaging over the star-forming galaxy population.