Planning secured for Anglesey Council to replace the derelict building with affordable housing units.