The ego is a cognitive function responsible for our brain's capacity to formulate a sense of self. The ego is the cognitive faculty that allows for self-awareness -- or the concept of an "I" to arise, as distinct from everything else. The ego, as self-awareness, is only comprised of conscious material (i.e. material we are aware of). Thus, the ego is, by definition, unaware of unconscious material and does not include this material into its self-awareness. That which is part of a person's psychological totality, but which is not mentally modeled or accounted for in ego awareness, is called the personal unconscious.
The ego function is a mental organization process which rallies together cognitive faculties into a hierarchy, as a complex. This complex is composed of the cognitive faculties that sit beneath it, and it utilizes these faculties to run wide-scale programs which are experienced qualitatively as a personality. The ego function does not necessarily produce only one complex with subordinate cognitive faculties. The ego function can produce oppositional hierarchies of cognitive faculties. When this happens, the person will have a duplicity in their personality. Each 'personality' in them will be the result of the ego function rallying together different cognitive faculties under an ego-complex.
The apparatus (Ji-Je-Pi-Pe) of a person is a cognitive complex; a hierarchical organization of lower cognitive faculties working under one unified aim. Those parts of our apparatus that exist in conscious awareness comprise an ego-complex. Thus, our apparatus is experienced qualitatively as a set of personalities. Metabolically, to be a type like TiSe is a description of a processing order. However, qualitatively TiSe is experienced as a personality (ego-complex); one that we sit within and exist through. At this level, it is inappropriate to treat the emergent results of the apparatus as metabolic programs, since they exist at the same level of reality as personality complexes. Thus, they are animate, have needs, voices, opinions and motivations -- insofar as the ego rallies together other cognitive faculties (speech, motor, etc) to represent their formulation. They can experience pain, anger, affirmation or rejection.
The shadow is an unconscious complex that likewise rallies together cognitive faculties, but into an unconscious complex or personality. The contents of the unconscious mind are not entirely disorganized, but come together, like the ego, into a hierarchical organization in order to mobilize needs. Unconscious psychological needs will rally together cognitive faculties and conjoin them together into an operative agent. This operative agent works unconsciously to meet the needs that the ego-complex is not attending to.
The construction of the shadow happens much like the construction of the ego. The shadow is the result of the ego function working outside of its own awareness. It organizes motivational systems together like the ego, but does so with less deliberation. Thus, the shadow will be an amalgamation of repressed content, loosely organized, but organized nonetheless. The shadow, as a personality, will be antithetical to the ego. In the case that a person has a thetic (lead+aux) development, the antithetical functions can form an unconscious complex with its own personality.