NGC 7129 FIRS 2 is a young intermediate-mass (IM) protostar, which is associated with two energetic bipolar outflows and displays clear signs of the presence of a hot core. It has been extensively observed with ground based telescopes and within the WISH guaranteed time Herschel key program. This paper is dedicated to the modeling of the C
18O and HDO lines in NGC 7129 FIRS 2. Our goal is to investigate the chemistry in the envelope and hot core of this IM protostar. We present new observations of the C
18O 3->2 and the HDO 3
12->2
21 lines towards NGC 7129 FIRS 2. Combining these observations with Herschel data and modeling their emissions, we constrain the C
18O and HDO abundance profiles across the protostellar envelope. In particular, we derive the abundance of C
18O and HDO in the hot core. The intensities of the C
18O lines are well reproduced assuming that the C
18O abundance decreases through the protostellar envelope from the outer edge towards the centre until the point where the gas and dust reach the CO evaporation temperature (≃20-25K) where the C
18O is released back to the gas phase. Once the C
18O is released to the gas phase, the modelled C
18O abundance is found to be ≃1.6x10
–8, which is a factor of 10 lower than the reference abundance. This result is supported by the non-detection of C
18O 9->8, which proves that even in the hot core (T
k>100K) the CO abundance must be 10 times lower than the reference value. Several scenarios are discussed to explain this C
18O deficiency. One possible explanation is that during the pre-stellar and protostellar phase, the CO is removed from the grain mantles by reactions to form more complex molecules. Our HDO modeling shows that the emission of HDO 3
12->2
21 line is maser and comes from the hot core (T
k>100K). Assuming the physical structure derived by Crimier et al. (
2010A&A...516A.102C), we determine a HDO abundance of ∼0.4-1x10
–7 in the hot core of this IM protostar. Herschel data combined with ground based observations have allowed us to estimate the C
18O and HDO abundance in the protostellar envelope and hot core of an IM protostar. The HDO abundance in the hot core is ∼0.4-1x10
–7, similar to that found in the hot corinos NGC 1333 IRAS 2A and IRAS 16293-2422. The C
18O abundance, at ≃1.6x10
–8, is a factor of 10 lower than the reference value.