When my husband died, I had a terrible struggle trying not to lose my spirit.
Literal
Husband [by-に] died-on [when-とき], I [topic-は] spirit [object-を] lose-not-intend do [for-のに] greatly struggled [polite-ました].
失うまいとする = 'to try not to lose' — まい is a literary/formal negative volitional. ~のに大変苦労しました = 'had great difficulty in doing.' A deeply personal expression of resilience.