Some amount of screaming has to be tolerated and should be accepted. It is natural for parrots to scream and they should be allowed to scream certain times of the day. If you can't accept the fact that all parrots scream, chatter, and screech then having a parrot as a pet is not right for you. Birds will scream when they become frightened. Any unusually loud screaming should be immediately investigated.
Cockatiels are know to have nightfrights when they become startled.
I recommend using a soft nightlight in your bird's room to reduce the chance of injury if your bird becomes startled during the night. Birds who scream because they are lonely may benefit from having another bird for companionship if the owners can't give the bird the amount of attention that the bird needs. The companion bird does not necessarily have to be a mate, but can be another bird kept in a separate cage. Using punishment as a source for training is not a good idea. Yelling, hitting the bird, hitting the cage, withholding food, leaving the bird in the cage all the time, will only serve to teach your bird not to trust you and this will ruin the relationship.