Optimal stability for inverse elliptic boundary value problems with unknown boundaries