Joint maintenance and spare parts inventory optimization has attracted increasing attention in recent years because of its capability in addressing the maintenance planning and the spare parts provisioning of industrial systems simultaneously. However, imperfect maintenance (IM) actions are either neglected or over-simplified as constant improvements in existing studies, which reduces their practicality in industrial applications. To tackle this limitation, this paper investigates the joint maintenance and spare parts inventory optimization for multi-unit systems with the consideration of IM actions as random improvement factors. First, a two-step approximate derivation method is proposed, which overcomes the derivation difficulties of replacement numbers due to the introduction of random improvement factors and enables the construction of the inventory level transition relationship. Then based on the inventory level transition relationship, an expected total cost model is formulated via the finite horizon stochastic dynamic programming (FHSDP). The decision variables are optimized by the joint use of enumeration and the FHSDP. Finally, a numerical simulation of a wind farm is carried out for illustration. Sensitivity analyses are further conducted to study the influences of critical parameters.