Yes, both sentences are grammatically correct. They convey the same meaning, but they use different verb tenses.
The first sentence, "I used to learn Italian while I was working in Rome," uses the past progressive tense ("was working") and the past simple tense ("used to learn") to indicate that learning Italian was a regular or habitual action in the past.
The second sentence, "I learnt Italian while I was working in Rome," uses the past simple tense ("learnt") to indicate a completed action in the past. It suggests that you finished learning Italian during the time you were working in Rome.
Both forms are commonly used, and the choice between them depends on the specific context and emphasis you want to convey.