The solution to your problem is two fold. First of all, anyone who has had a cat knows that trying to punish them is futile. They just don't care. Therefore, you want to reward positive behaviors and at the same time eliminate the circumstances that leads to the behaviors you want to eliminate. Be sure to keep the litter box clean and available, giving praise when he uses it, second, if he pees when you leave bags on the floor, don't. If the worst case scenario is that you cannot change your cats behavior, you can change your own and eliminate the temptation for him to pee on bags by not presenting him with the opportunity.