Optimization problems for solutions of elliptic equations and stability issues