both the molecules are too small and have no charge therefore they can move across a membrane via gradient pressure from higher concentration to lower via simple diffusion. they don't need any atp or energy.
Bacteria that obtain its carbon from carbon dioxide (inorganic source) and its energy from complex carbon is known as chemotherapeutic bacteria. and the type mention in the above statement is known as chemolithoautotrophs.