Sometimes relaxing your expectations can help.
Before you let something get to you ask yourself if it's really important.
What is your 'mission statement' as it were, for parenting your children? Is it that they will learn to do as they are told when they are told and give you no trouble or that you will teach them how to be respectful, decent human beings and to make the right decisions as much as possible?
I think, as parents, many of us get too wrapped up in the first one. So many people think that a child 'doing as they are told' is the optimum Good Child, but is it really?
Your children behave well in their learning environment, so they obviously have respect for authority and understand learning is important. I'd also say that most children who do 'as they are told' at school, do NOT do it for the teachers, but because they know how important school and learning and respecting adults is from their parents so you must be doing something right.
The reason they are acting out at home is, as others have said, because they feel safe and secure to get any frustration and tension out in that environment, again, a Good Thing, not something you have done 'wrong'.
Start off by being a bit easier on yourself and decide what you really cannot compromise on, and what you can compromise on.