Stencil lithography is used for patterning and connecting nanostructures with metallic microelectrodes in ultrahigh vacuum. Microelectrodes are fabricated by static stencil deposition through a thin silicon nitride membrane. Arbitrary nanoscale patterns are then deposited at a predefined position relative to the microelectrodes, using as a movable stencil mask an atomic force microscopy (AFM) cantilever in which apertures have been drilled by focused ion beam. Large scale AFM imaging, combined with the use of a high precision positioning table, allows inspecting the microelectrodes and positioning the nanoscale pattern with accuracy better than 100 nm.