On the Optimality, Stability, and Feasibility of Control Barrier Functions: An Adaptive Learning-Based Approach