Optimization of impurity profile for p-n-junction in heterostructures