The problem of maximizing the thermal insulation of buildings is dealt with, by determining the geometry of masonry blocks that minimizes the transmittance of any wall. Assuming the heat flux to be uniform across the wall surfaces, topology optimization is employed to define the layout of the block section. Constraints on the block stiffness are also prescribed. The presence of holes of given shape in any prescribed position and other technological constraints can be easily embodied in the optimization procedure. The effect of the design constraints on the optimal layout of the blocks is investigated. The thermal efficiency of the optimized units is also compared with that of commercially available blocks