Dynamic spectrum sharing aims to provide flexible spectrum usage and improve spectrum efficiency for cellular and noncellular networks. We propose two optimization models using stochastic optimization algorithms in which the secondary operator: 1) spends the minimal cost to achieve the target grade of service (GoS) assuming unrestricted budget or 2) gains the maximal profit to achieve the target GoS assuming restricted budget. We assume that there are spectrum resources available for secondary operators to borrow under a merchant mode. Results obtained from each model are then compared with results derived from algorithms in which spectrum borrowings are random. Comparisons showed that the gain in the results obtained from our proposed stochastic-optimization framework is significantly higher than heuristic counterparts. Second, post-optimization performance analysis of the operators in the form of blocking probability in various scenarios is investigated to determine the probable performance gain and degradation of the secondary and primary operators, respectively. We mathematically model the sharing agreement scenario and derive the closed-form solution of blocking probabilities for each operator. Results show how the secondary operator performs in terms of blocking probability under various offered loads and sharing capacity.