BPS Action and Superpotential for Heterotic String Compactifications with Fluxes