Electronic structure and magnetic behaviour of ultrathin epitaxial films and nanostructures on surfaces