Optical vs. infrared studies of dusty galaxies and AGN: (I) Nebular emission lines