An iconic former shop building in the heart of Lesmahagow is to be transformed into a new marketplace and affordable housing.