Can I be convicted by a judge for something that is today legal? Where
everyone in the court room, including the judge, would be allowed to
do it today? Does it make a difference if I got caught before or after
the law change? Would a judge have legal leeway (that is it's up to
him to decide if I should be prosecuted or not?) If I was already
convicted, would I have reasons for an appeal with the argument that
my actions are not illegal (anymore)?
Context would matter, but usually, the answer would be yes, you could be convicted, even if you were arrested after the change in the law. The judge would have no say in the matter and this would not generally be a ground for appeal.
For example, suppose that you were charged with failing to honor a curfew imposed in the aftermath of a Hurricane and that curfew has now been lifted. You could still be prosecuted and convicted for violating the curfew.
Similarly, suppose that you are convicted of possessing heroin in 2017, but in 2018 heroin is legalized, and the case against you for possession of heroin is prosecuted in 2019. You could be convicted of heroin possession in 2019 as a matter of federal constitutional law in the U.S., even though many prosecutors would decline to press charges in those circumstances, even though a jury might be inclined to engaged in jury nullification, and even though some state constitutions or state jurisprudence might discourage or forbid this prosecution.
There is something subtly different which doesn't really line up with your question but is easily confused for it.
Suppose that you are convicted of a crime, but after your conviction, a court holds as a binding precedent in another case, that the crime that you were convicted of is unconstitutional or otherwise invalid in your circumstances (e.g. in a U.K. scenario, you are convicted of trespassing on the walkway to someone's front door since that is private property, but a later precedent hold that members of the public are legally entitled to use such a walkway unless there is a "no trespassing" sign posted which no one disputes wasn't present in your case).
As a matter of constitutional U.S. law, your conviction remains valid and you must serve the sentence, if your conviction was final and all appeals had been exhausted when the new court decision was announced unless it was a "new rule" of law rather than a mere interpretation of existing law, but if your conviction was not yet final because post-conviction motions or appeals were still pending, the new rule of law could be utilized to challenge your conviction. Under the U.S. Constitution, "new rules" have retroactive effect, while interpretations of existing law do not.
In France, in contrast, the constitution states that all people convicted of crimes that cease to be crimes under a change in the law, are entitled to benefit from the change in the law.
I don't know what English law says about this question.