Thanks!
How about Ich habe für zwei Jahre Deutsch gelernt?*
*I'd have added "ins Schule" before "für", but not sure if that's correct
Depends:
If you want to say: "I have been learning German for two years" (which means you are still doing so), then it is: "Ich lerne seit zwei Jahren Deutsch."
If you want to say: "I used to learn German for two years" (which means you are doing so no more), then it is: "Ich habe zwei Jahre lang Deutsch gelernt."
So your sentence would be either "Ich lerne seit zwei Jahren Deutsch in der Schule" (you could put "in der Schule" also before "seit" or "Deutsch)
or "Ich habe zwei Jahre lang in der Schule Deutsch gelernt". (you could also put "in der Schule" at the end of the sentence or before "zwei")
Note that "for" doesn't mean "für", but "seit". Also, "for two years" means "zwei Jahre lang" or "seit zwei Jahren". It's a bit tricky.