They are verbs that are used when describing situations in which you can't decide what to do or which one to chose. They are interchangeable in many cases, but the nuance is slightly different.
"迷う" indicates the process of deciding between two or more different things.
On the other hand, "悩む" indicates a struggle in the process of deciding between two or more different things.
- Meg: I'll have a medium coffee to go. How about you?
持ち帰りで、Mサイズのコーヒーにする。エイミは? - Amy: Hmm, I can't decide what to order. I'd like a mocha or matcha latte.
んー、迷う。モカか抹茶ラテがいいな。
--> Since it looks like she just thinks which one to choose, you can use "迷う". If it looks like she struggles with it, you can use "悩む". - Meg: Which one are you going to order?
どっちにするの? - Amy: I'll gor for a matcha latte because it goes well with the dorayaki I bought for snack time.
抹茶ラテにする。おやつに買ったどら焼きに合うから。
- Leo: What's on your mind?
どうした? - Ken: I'm having a hard time dealing with politics at the office. My boss says I need to train my subordinates as soon as I can, but I think it will take sometime because they don't listen to others.
会社の人間関係に悩んでいるんだ。上司に、出来るだけ早く部下を育てるよう言われているけど、(部下は)人の話を聞かないから、時間がかかりそうだよ。
--> Since he is stressed out about how to deal with the problem, you can use "悩む".
- Meg: I saw Mike with another girl several times. I think he is cheating on Kumi.
マイクが他の女の子といるのを、何回か見たの。浮気していると思う。 - Amy: I think so too, but I don’t know if I should tell her the truth. I know it's the right thing to do, but I don't want her to get hurt. I'm torn.
私もそう思うけど、クミに本当の事を言うべきか分からないよ。教えた方がいいんだろうけど、(彼女を)傷つけたくないし。悩むー。
--> Since she's worried whether to tell the truth or not, you can use "悩む".