You are talking about getting guardianship of a minor -- something that is pretty thoroughly explained here.