First-principles calculations for defects and impurities: Applications to III-nitrides