I reject the idea that law enforcement is always necessary. Laws are frequently unjust and anti-solarpunk. I don't care about people breaking laws if the laws don't serve the people. But let's say all the laws are just - I also reject the idea that we need a bunch of power-hungry assholes with weapons and legal immunity to "enforce" them.
Here's the thing - we rely on the police to do a broad range of tasks and, at least in the US, we hand them a gun to do all of those tasks. The traffic lights are down? Take your gun and go stand in the intersection. Parking tickets? You'll need your gun for that. Homeless people on the streets? Don't forget your gun. House broken into? Here's a gun, try not to shoot the wrong person.
The simple answer is that we should have a different team of (trained, specialized) people for each of those scenarios. Police don't receive training in each of those areas which means they are frequently in danger and frequently relying on violence or the threat of violence to get things done. It's not fair to the officers and its not fair to the people they "serve." I want to see a team who handles traffic, a team to respond to homeless people (though hopefully we'll be on our way to finally providing housing for all), a separate team for crimes like burglary and theft, etc etc.
Here's a resource for you (and others) to check out, they explain things much more succinctly than me: https://defundthepolice.org/alternatives-to-police-services/
As for a military - I will be completely honest, I haven't educated myself as much on alternatives to that, but I do question your assumption that we will always need to defend ourselves. It assumes that people will always be attacking us.