Electronic and structural properties of semiconductor-metal and semiconductor-insulator interfaces