A Bayesian Approach for Characterizing and Mitigating Gate and Measurement Errors