Anisotropic contribution to the van der Waals and the Casimir-Polder energies for CO2 and CH4 molecules near surfaces and thin films