Necessary and Sufficient Conditions for the Lower Semicontinuity of Certain Integral Functionals