Connected and autonomous vehicle technologies are expected to alter transportation systems by enhancements in mobility, safety, and emission reduction. While many studies have investigated the impacts of connected vehicle (CV) and autonomous vehicle (AV) technologies on traffic congestion and emission at the facility level, little is known about these impacts at large scales. Furthermore, different effective parameters associated with these impacts, such as the extra vehicle miles traveled (VMT) induced by AVs, technology cost of these vehicles, and possible reductions in the value of time of AV users, are highly uncertain. The uncertainty of these parameters and its role in assessing the societal impacts of CVs and AVs are not fully explored in the literature. Therefore, this study aims to develop a stochastic framework and an optimization algorithm to find the optimum market shares of CVs and AVs in a mixed traffic environment, consisting of human-driven vehicles without connectivity (HDVs), CVs, and AVs, minimizing the system cost. Emission, travel time, and technology costs are considered as components of the system cost. Thus, the framework combines a traffic simulation tool that considers a mixed fleet of HDVs, CVs, and AVs with heterogeneous drivers (for HDVs and CVs) distributed spatially over the network, along with an emission estimation model, to measure network-wide travel time and emission costs. Many parameters, such as extra VMT produced by AVs, value of time reduction for AV users, and automation cost, are subject to a considerable degree of stochasticity, which is considered by assuming probabilistic distributions for these parameters. A Bayesian Optimization algorithm with heteroskedastic non-stationary Gaussian process model is presented to estimate the optimum market shares of CVs and AVs considering these uncertainties. The stochastic framework and the optimization algorithm are successfully applied to a large-scale network of Chicago. The impacts of different parameters on the optimum CV and AV market shares and the system cost are explored, providing practical insights for policymakers.