You need to apply for planning permission when building a granny flat from scratch, or for change of use when converting and outbuilding.