With the rapid development of microgrid, its tie-line switching from grid-connected to islanded mode is a topic worth discussing for considering both main grid resilience and microgrid security. In this paper, a stochastic security-constrained optimal power flow (OPF) method is proposed to deal with these conditions under high uncertainties. Firstly, a linear load flow model and a backward forward sweep algorithm are applied to present microgrid power flow with reduced computing burdens. Secondly, with consideration of tie-line switching from grid-connected to islanded operation mode, a security-constrained OPF problem for a microgrid is proposed to minimize operating cost and by optimizing microturbine setpoints and load shedding coefficient. To promise stable islanded operation after disconnection from the main grid, a Benders decomposition method is developed to decouple the OPF problem into a grid-connected master problem and an islanded sub-problem and then solve them iteratively with Benders cuts to guarantee microgrid security after tie-line switching. Last, a stochastic optimization method with probabilistic modelling is adopted to address the uncertainty issue caused by renewable energy sources and loads. The proposed stochastic security-constrained OPF method has been verified with high computing efficiency and robust security via comprehensive numerical simulations.