First-principle study of metal oxide thin films: Electronic and magnetic properties of confined d electrons