You must realize that you are not the only one in this predicament. We get this question on this forum over and over again from wonderful caring women who want to have healthy babies. Xanax is the one medication that is an absolute no-no in pregnancy.
You must talk to your OB/GYN. They will need to decide how to taper you off the Xanax quickly. They treat many women in exactly the same situation and will be able to refer you to a physician who will most likely put you on a medication called Suboxone or Subutex and will over a few months taper you if you will need it. However if you are not on such a high dose of opiates you might be able to just slowly taper it off by yourself, so that your baby will withdraw slowly with you without any problems. By tapering I mean cutting the dose and prolonging the time between doses until you only take at night, then none. However, because of your chronic pain issues they may need to keep you on Subutex in order to control your pain. It is entirely possible to have a healthy pregnancy, childbirth and nursing experience while on Subutex. The baby will not have to go through any withdrawals and will slowly get weaned while weaning off of breast milk.
You need to quit smoking as well (if you do), because it leads to decreased baby weight and higher incidence of early labor. Please see you doctor ASAP. If you feel that you cannot be open and honest with him/her, than find another one. May be this is not the right OB for you if you cannot trust him/her enough to talk about such an important issue. Good luck to you and your growing family. You must take care of yourself for your baby.
P.S. Please read my blog on Pregnancy and Addiction