Cost-Aware Learning and Optimization for Opportunistic Spectrum Access