How could I compute the total baryonic mass and total DM mass for the TNG300-2 simulated box in a redshift z=0? I did not find these values in the documentation.
Do you mean in the entire simulation? You could compute these using the cosmological parameters (e.g. Omega_b and Omega_m).
More straightforward, you can just load the Masses field for all particles of types 0,4,5 for the baryons, and MassTable*NumPart (from the Header of the snapshot) for the dark matter.