There’s a couple of differences. Firstly, ために can be used with any verb in the main clause, while V-stem+に can only be used with motion verbs. Unless it’s pretty clear from the context, you can’t use ために without a destination (e.g. 食べ物を買うためにスーパーに行きます), while V-stem+に has no such restriction.
In general, though, you’d usually only use ために if the purpose is significant or important – which is to say, going to school to learn Japanese is important, while going to to cafe to get a drink is not. It wouldn’t be ungrammatical to use ために for the latter, just a bit odd.