Template-Guided 3D Molecular Pose Generation via Flow Matching and Differentiable Optimization