We study a joint assortment and inventory optimization problem faced by an online retailer who needs to decide on both the assortment along with the inventories of a set of N substitutable products before the start of the selling season to maximize the expected profit. The problem raises both algorithmic and modeling challenges. One of the main challenges is to tractably model dynamic stock-out based substitution where a customer may substitute to the most preferred product that is available if their first choice is not offered or stocked-out. We first consider the joint assortment and inventory optimization problem for a Markov Chain choice model and present a near-optimal algorithm for the problem. Our results significantly improve over the results in Gallego and Kim (2020) where the regret can be linear in T (where T is the number of customers) in the worst case. We build upon their approach and give an algorithm with regret O˜(√NT) with respect to an LP upper bound. Our algorithm achieves a good balance between expected revenue and inventory costs by identifying a subset of products that can pool demand from the universe of substitutable products without significantly cannibalizing the revenue in the presence of dynamic substitution behavior of customers. We also present a multi-step choice model that captures the complex choice process in an online retail setting characterized by a large universe of products and a heavy-tailed distribution of mean demands. Our model captures different steps of the choice process including search, formation of a consideration set and eventual purchase. We conduct computational experiments that show that our algorithm empirically outperforms previous approaches both on synthetic and realistic instances.