We study the dependence of the galaxy content of dark matter halos on large-scale environment and halo formation time using semi-analytic galaxy models applied to the Millennium simulation. We analyze subsamples of halos at the extremes of these distributions and measure the occupation functions for the galaxies they host. We find distinct differences in these occupation functions. The main effect with environment is that central galaxies (and in one model also the satellites) in denser regions start populating lower-mass halos. A similar, but significantly stronger, trend exists with halo age, where early-forming halos are more likely to host central galaxies at lower halo mass. We discuss the origin of these trends and the connection to the stellar mass -- halo mass relation. We find that, at fixed halo mass, older halos and to some extent also halos in dense environments tend to host more massive galaxies. Additionally, we see a reverse trend for the satellite galaxies occupation where early-forming halos have fewer satellites, likely due to having more time for them to merge with the central galaxy. We describe these occupancy variations also in terms of the changes in the occupation function parameters, which can aid in constructing realistic mock galaxy catalogs. Finally, we study the corresponding galaxy auto- and cross-correlation functions of the different samples and elucidate the impact of assembly bias on galaxy clustering. Our results can inform theoretical models of assembly bias and attempts to detect it in the real universe.