Optimization approach to entanglement distillation