Preliminaries: Your question touches the connection of statistical mechanics with combinatorics and number theory, see e.g. Ref. 1. I think it is not possible to give a definite answer to your question, i.e. as far as I know there is no closed expression which would answer your question in full generality.
However, below we will also investigate some models to see how your problem can be reduced to a combinatorial question, some of which can be given an implicit solution, e.g. in terms of generating functions. I will also give some references for further reading.
In every case below, we will consider a system of $N$ non-interacting particles, which means that the many-body Hamiltonian takes the form $H=\sum\limits_{i=1}^N h_i$, where $h_i$ is the Hamiltonian of the $i$-th particle.
The basic idea in all cases will be that we will put basis elements into a one-to one correspondence with sequences of numbers, which allows us to get the dimension of the eigenspace corresponding to some eigenvalue by counting the number of sequences which fulfill some constraint.
A: $N$ distinguishable harmonic oscillators in one-dimension
I think it is instructive to first start with distinguishable particles. The single-particle Hamiltonian admits a complete orthonormal basis, denoted by $\{|n\rangle\}_{n\in \mathbb N_0}$ with corresponding energies $\epsilon_n=n$ (omitting with out loss of generality additive and multiplicative positive constants). The $N$-particle Hilbert space is the $N$-fold tensor product of the single-particle Hilbert space and hence an orthonormal basis for this space is given by
$$\{|n_1\rangle\otimes |n_2\rangle\otimes \cdots \otimes|n_N\rangle\}_{n_1,n_2,\ldots,n_N\in \mathbb N_0} \tag 1\quad ,$$
which is also the eigenbasis of the many-particle Hamiltonian $H$. As it is easily shown, every state of the above basis has an energy equal to
$$E=\sum\limits_{i=1}^N n_i \tag 2 \quad .$$
You now ask for the dimension of the eigenspace of an arbitrary given eigenvalue $E$, denoted by $\dim E(N)$, which is simply the number of elements of $(1)$ with the same energy. Thus, your question can be reformulated as the number of ways to write a non-negative integer $E$ as a sum of $N$ non-negative numbers. This is the problem of weak-k-composition of a number. The answer, which can readily be obtained e.g. with the method of stars and bars (see also the link), is hence $$\dim E(N)=\binom{E+N-1}{N-1} \quad. \tag 3$$
If you check the above link, you will notice that by similar reasoning you can also obtain the case where all $n_i\in \mathbb N$ instead. Finally, let me remark that compositions treat e.g. $4=3+1$ and $4=1+3$ as different compositions of the number $4$, which naturally reflects the physics of distinguishable particles.
B: $N$ indistinguishable harmonic oscillators in one-dimension
Let us now study the case of identical (spinless) bosons and fermions, while the single-particle setting remains the same. An orthonormal eigenbasis of the many-body Hamiltonian for the bosonic case is given by
$$\{c^B(n_1,n_2,\ldots,n_N)\,S_N|n_1\rangle\otimes |n_2\rangle\otimes\cdots \otimes |n_N\rangle\}_{n_1\leq n_2\leq\ldots \leq n_N} \quad , \tag 4$$
with $n_j\in \mathbb N_0$ for $j=1,2,\ldots, N$, $c^B(n_1,n_2,\ldots,n_N)>0$ a normalization factor and $S_N$ the symmetrization operator of $N$ particles. Each state of this basis has an energy equal to $(1)$. The difference to the previous case is that the basis naturally encapsulates the indistinguishability of the particles, and hence also modifies the corresponding combinatorial problem, which now asks:
Given a non-negative integer $E$, how many sequences of $N$ non-decreasing and non-negative integers do exist such that their sum yields $E$? Equivalently, this is the number of ways to write $E$ as a sum of at most $N$ natural numbers (ignoring order), which is (an instance of) the problem of partition in number theory. This number then is equal to the number of partitions of $E+N$ into exactly $N$ natural numbers. Let $p_N(E)$ denote this number.
For fermions, an orthonormal basis if given by
$$\{c^F(n_1,n_2,\ldots,n_N)\,A_N|n_1\rangle\otimes |n_2\rangle\otimes\cdots \otimes |n_N\rangle\}_{n_1<n_2<\ldots <n_N} \quad , \tag 5$$
with $n_j\in N_0$ for $j=1,2,\ldots, N$, $c^F(n_1,n_2,\ldots,n_N)>0$ a normalization factor and $A_N$ the anti-symmetrization operator of $N$ particles. Each state again has an energy $(1)$ and your question now can be framed as:
Given a non-negative integer $E$, how many sequences of $N$ strictly increasing and non-negative integers do exist such that their sum equals $E$? Equivalently, you can ask for the number of ways (ignoring order) to write $E+N$ as a sum of exactly $N$ natural numbers which are all different, i.e. you ask for the number of k-partitions with the restriction that no element of the partition should repeat.
Note that in contrast to the case of distinguishable particles, partitions (as opposed to compositions) regard $4=3+1$ and $4=1+3$ as the same decomposition.
As a final remark here, let me mention that a generating function for $p_N(E)$ is related to the canonical partition function (Zustandssumme) of $N$ identical bosons in a harmonic oscillator potential, which I've derived some time ago here.
This is shown in reference 2, where also an asymptotic relation for $p_N(E)$ is given. For the fermionic case, see references 2 and 5.
C: $N$ distinguishable particles in a one-dimensional box (ideal gas)
Here, we will distinguish two boundary conditions. First, we consider periodic boundary conditions, where the single-particle energies are given by $\epsilon_k=k^2$ (omitting again irrelevant constants) with $k\in \mathbb Z$. The many-body Hamiltonian admits an orthonormal eigenbasis obtained from the $N$-fold tensor product of the eigenbasis of the single-particle Hamiltonian:
$$ \{|k_1\rangle\otimes |k_2\rangle\otimes \cdots\otimes |k_N\rangle\}_{k_1,k_2,\ldots,k_N \in \mathbb Z} \tag 7 \quad .$$
Each of these states has an energy equal to
$$ E=\sum\limits_{i=1}^N k_i^2 \quad , \tag 8$$
and hence your question asks for the number of ways to write a non-negative integer $E$ as a sum of squares of $N$ integer numbers. The answer is the sum of squares function from number theory, see also Wikipedia. It admits a representation in terms of generating functions, which I refrain from reproducing here, as it is given in the link, with some more explicit formulas for certain special cases.
If I had to guess, I'd say that the generalization to three-dimensions should be straightforward, but you should double check.
Next, we can also consider hard walls, i.e. particles in a box with infinite potential at the walls. The single-particle energies read $\epsilon_n=n^2$, for $n\in \mathbb N$. I refrain from repeating basically the same procedure as above and we just note that hence the question now asks for the number of ways to write a natural number $E$ as a sum of squares of $N$ natural numbers.
I don't know if this has a solution (either explicit or implicit in terms of generating functions or similar).
D: $N$ indistinguishable particles in a one-dimension box (ideal gas)
It should now be evident how to phrase the questions for identical bosons and fermions.
Unfortunately, I don't know of any solution to this problem in a form similar to the above problems. However, reference 3 and 4 discuss some asymptotic (related) cases which might be of interest to you.
References and further reading:
- physics- and probability-related approaches to
integer partitioning problems. Link.
- F. C. Auluck and D. S. Kothari. Statistical mechanics and the partitions of numbers. 1946. Link
- B. K. Agarwala and F. C. Auluck. Statistical mechanics and partitions into non-integral powers of integers. 1951 Link
- H. N. V. Temperley. Statistical Mechanics and the Partition of Numbers. I. The Transition of Liquid Helium. 1949. Link
- Kubasiak, A. et al. Fermi-Dirac statistics and the number theory. 2005. Link
- Zhou, Chi-Chun, and Wu-Sheng Dai. A statistical mechanical approach to restricted integer partition functions. 2018. Link
- A. Rovenchak. Statistical mechanics approach in the counting
of integer partitions. 2016 Link