MoE$^2$: Optimizing Collaborative Inference for Edge Large Language Models