Generally when you have a foul odor when flushing the toilet it means the toilet wax ring is not sealed to the toilet or the floor. Whenever you put water into a drain, it first has to push the air away. If the wax ring is not sealed, it will simply push it between the floor and the bottom of the toilet into the room, instead of down the pipe. Because both air and water take up space in the pipe, you can't put the water in unless you move the air out. Typically we send it up the main vent of the house and out the roof, but if the roof vent is blocked, then there is no place for the air to go. To eliminate the bathroom odor, you should reseal the toilet to the floor and the clear the main vent of debris.