Hindsight is 20/20 or so I am told, the biggest mistake was in letting him out right away instead of allowing him a day or so to calm down. This is not really your fault because you did not know and the previous owner could have told you and easily have prevented this from occurring the first time and then again the second time. Also the first thing to do whenever a bird suffers injury is to take it to the vet. You can't look at a cracked beak and tell how much damage was done, it usually takes x-rays to do this. This is even more important to do now that it has further damaged its beak, so take it to the vet and follow his instructions.
Now when you bring a new bird home it is terrified as it is all alone in a strange new place which for a bird is nearly the same as a death sentence. It is no wonder that he flew about in a panic. The thing to do is hang out with them to reassure them with them in the cage so that it understands that although it doesn't yet trust you that you are there for it and if you offer a treat even if you have to leave it in its food dish it will start it learning that you are the bringer of good things. I would not have allowed the bird out of the cage until it begins to relax a bit in its new environment, but again the previous owner did not share any of this with you so you did not know these things. A few sheets hung up over things like windows or other places that the bird might fly into would help by acting as a cushion for the panicked bird. You could do this in a smaller room easier and the smaller room would prevent the bird from gaining as much speed thereby reducing the impact if it does fly into something.
So take the bird to the vet and follow his instructions and keep us informed and when you are ready to try letting the bird out of the cag or are ready to start working with your new friend let us know and we will be happy to help you in any way that we can.